package com.baizhi.filter;

import com.baizhi.entity.Admin;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        System.err.println("进入拦截器");
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        Admin admin = (Admin) request.getSession().getAttribute("login");
        if (admin==null){
            HttpServletResponse response = (HttpServletResponse)servletResponse;
            response.sendRedirect(request.getContextPath()+"/login.jsp");
        }else{
            chain.doFilter(servletRequest,servletResponse);
        }
    }
}
